{% load static %}
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>操作日志管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
    <script src="/static/js/flow-meter.js" charset="utf-8"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">
                    <cite>操作日志管理</cite>
                </a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-col-md1">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="begin_time"
                                   id="begin_time">
                        </div>
                        <div class="layui-inline layui-col-md1">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end_time"
                                   id="end_time">
                        </div>
                        <div class="layui-inline layui-col-md2">
                            <input type="text" name="username" placeholder="请输入操作人员名称" autocomplete="off"
                                   class="layui-input" id="username">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="opr_type" id="opr_type" lay-filter="opr_type">
                                <option value="">操作类型</option>
                                <option value="query">查询</option>
                                <option value="recharge">充值</option>
                                <option value="open_recharge">打开预充值</option>
                                <option value="close_recharge">关闭预充值</option>
                                <option value="open_valve">开阀</option>
                                <option value="close_valve">关阀</option>
                                <option value="set_meter_address">设置仪表物理地址</option>
                                <option value="set_flow_ratio">设置流量系数</option>
                                <option value="reset">重启仪表</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="state" id="state" lay-filter="state">
                                <option value="">操作状态</option>
                                <option value="wait">等待中</option>
                                <option value="success">成功</option>
                                <option value="error">失败</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table lay-filter="oprlog" id="oprlog">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-danger" lay-event="del_batch">
        <i class="layui-icon"></i>批量删除
    </button>
    <button class="layui-btn layui-btn-sm" lay-event="export">导出</button>
</script>
<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#begin_time' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end_time', //指定元素
        });

    });
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'element'],
        function () {
            $ = layui.jquery;
            table = layui.table;
            form = layui.form;

            table.render({
                elem: '#oprlog', //指定原始表格元素选择器（推荐id选择器）
                cols: [[
                    {checkbox: true, width: '5%', field: 'id', align: 'center'},
                    {
                        align: 'center',
                        numbbers: true,
                        width: '5%',
                        title: '序号',
                        templet: function (data) {
                            return data.LAY_INDEX;
                        }
                    },
                    {field: 'opr_user_name', title: '操作人员名称', align: 'center'},
                    {field: 'meter_dtu_dtu_no', title: 'DTU编号', align: 'center'},
                    {field: 'meter_address', title: '仪表物理地址', align: 'center'},
                    {field: 'opr_type', title: '操作类型', align: 'center'},
                    {field: 'val', title: '值', align: 'center'},
                    {field: 'state', title: '操作状态', align: 'center'},
                    {field: 'opr_time', title: '操作时间', align: 'center'},
                ]],
                url: '/handler/log/?action=query_opr_log',
                page: true,
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'print'],

            });

            //头工具栏事件
            table.on('toolbar(oprlog)',
                function (obj) {
                    switch (obj.event) {
                        case 'del_batch':
                            layer.confirm('确认要删除吗？', function (index) {
                                let checkStatus = table.checkStatus('oprlog');
                                let ids = [];
                                for (let i = 0; i < checkStatus.data.length; i++) {
                                    ids.push(checkStatus.data[i].id);
                                }
                                post({
                                    "param": JSON.stringify({'opr_log_ids': ids}),
                                    "action": "del_opr_log"
                                }, '/handler/log/', function (data) {
                                    if (!data.success) {
                                        layer.msg(data.msg, {icon: 5, time: 1000});
                                    } else {
                                        layer.msg('删除成功!', {icon: 1});
                                        table.reload('oprlog');
                                    }
                                });
                            });
                            break;
                        case 'export':
                            let checkStatus = table.checkStatus('oprlog');
                            let ids = [];
                            for (let i = 0; i < checkStatus.data.length; i++) {
                                ids.push(checkStatus.data[i].id);
                            }
                            post({
                                "param": JSON.stringify({'oprlog_ids': ids}),
                                "action": "export_opr_log"
                            }, '/handler/log/', function (res) {
                                if (!res.success) {
                                    layer.msg(res.msg, {icon: 5, time: 3000});
                                } else {
                                    let param = JSON.stringify({
                                        "filename": res.data,
                                    });
                                    let action = 'download_file';
                                    window.open('/handler/file/?param=' + param + '&action=' + action);
                                }
                            });
                            break;
                    }
                });
            //监听提交
            form.on('submit(search)',
                function (data) {
                    table.reload('oprlog', {
                        "where": {
                            "param": JSON.stringify(data.field),
                        }
                    });
                    return false;
                });


        });
</script>
<script>var _hmt = _hmt || [];
(function () {

})();</script>

</html>